function populateFields(row) {
	document.getElementById("id").value = row.cells[0].innerHTML;
	document.getElementById("firstName").value = row.cells[1].innerHTML;
	document.getElementById("lastName").value = row.cells[2].innerHTML;
	if (row.cells[3].innerHTML == "null")
		document.getElementById("homeNumber").value = ""
	else
		document.getElementById("homeNumber").value = row.cells[3].innerHTML;
	document.getElementById("cellNumber").value = row.cells[4].innerHTML;
	document.getElementById("email").value = row.cells[5].innerHTML;
	document.getElementById("address").value = row.cells[6].innerHTML;
	document.getElementById("position").text = row.cells[8].innerHTML;
	document.getElementById("position").value = row.cells[10].innerHTML;
	if (row.cells[7].innerHTML == "true")
		document.getElementById("relocation").checked = true;
	else
		document.getElementById("relocation").checked = false;

}

function validateFields(clicked_id) {
	var firstName = document.getElementById("firstName");
	var lastName = document.getElementById("lastName");
	var address = document.getElementById("address");
	var cellNumber = document.getElementById("cellNumber");
	var email = document.getElementById("email");
	var homeNumber = document.getElementById("homeNumber");
	var cv = document.getElementById("cv");

	if (firstName.value == "" || firstName.value.length>45 ) {
		alert(document.getElementById("emptyfilledfirstname").name);
		document.getElementById("firstName").focus();
		return false;
	}

	if (lastName.value == "" || lastName.value.length>45) {
		alert(document.getElementById("emptyfilledlastname").name);
		document.getElementById("lastName").focus();
		return false;
	}
	
	if (homeNumber.value.length != 13 && homeNumber.value.length != 0) {
		alert(document.getElementById("wrongfilledhomenum").name);
		document.getElementById("homeNumber").focus();
		return false;
	}

	if (cellNumber.value == "" || cellNumber.value.length>45) {
		alert(document.getElementById("emptyfilledcellnum").name);
		document.getElementById("cellNumber").focus();
		return false;
	}
	
	var reCell = /^\d{13}/;
	if (reCell.test(cellNumber.value) == false) {
		alert(document.getElementById("wrongfilledcellnum").name);
		document.getElementById("cellNumber").focus();
		return false;
	}

	if (email.value == "" || email.value.length>45) { 
		alert(document.getElementById("emptygfilledmail").name);
		document.getElementById("e-mail").focus();
		return false;
	}
	
	var reEmail = /^[a-zA-Z]+[a-zA-Z.+_0-9]+@[a-zA-Z.]/;
	if (reEmail.test(email.value) == false) {
		alert(document.getElementById("wrongfilledmail").name);
		document.getElementById("email").focus();
		return false;
	}

	if (address.value == "" || address.value.length>45) {
		alert(document.getElementById("emptyfilledadress").name);
		document.getElementById("address").focus();
		return false;
	}	
	
	
	
	if (!cv.value && clicked_id=="insert" ) {
		alert(document.getElementById("emptyfilledcv").name);
		document.getElementById("cv").focus();
		return false;
	}

	return true;
}

function clearFields() {
	document.getElementById("id").value="";
	document.getElementById("firstName").value = "";
	document.getElementById("lastName").value = "";
	document.getElementById("cellNumber").value = "";
	document.getElementById("homeNumber").value = "";
	document.getElementById("email").value = "";
	document.getElementById("address").value = "";
	document.getElementById("relocation").checked = false;

}
